package com.yanqu.road.server.cmd.variety;

import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.variety.VarietyProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.match.CrossMatchMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/2/6 18:32
 */
@Cmd(code = CrossProtocol.C_VARIETY_DISPATCH_TEAM, desc = "派遣队伍")
public class DispatchTeamCrossCmd extends CrossCommand {
    private VarietyProto.DispatchTeamCrossReqMsg msg;
    private VarietyProto.DispatchTeamCrossRespMsg.Builder respMsg;
    private long playerId;
    @Override

    public boolean parseData(YanQuMessage packet) throws Exception {
        msg = VarietyProto.DispatchTeamCrossReqMsg.parseFrom(packet.getBytes());
        playerId = packet.getPlayerId();
        respMsg = VarietyProto.DispatchTeamCrossRespMsg.newBuilder();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        for (VarietyProto.PatronsTemp patronsTemp : msg.getPatronsList()) {
            respMsg.addPatronsId(patronsTemp.getPatronsId());
        }
        respMsg.setId(msg.getId());
        respMsg.setLevel(msg.getLevel());
        respMsg.setMatchId(msg.getMatchId());
        CrossMatchMgr.dispatchTeam(serverId, playerId, msg, respMsg);
    }

    @Override
    public void sendData() {
        YanQuMessage message = YanQuMessageUtils.buildMessage(GameProtocol.S_VARIETY_DISPATCH_TEAM_FROM_CROSS, respMsg);
        MessageHelper.sendPacket(serverId, playerId, message);
    }
}
